<?php
class CodeGenerator extends TemplateEngine_base
{
	public function home_action()
	{
		$tables = $this->getTables();
		$arr = array();
		foreach($tables as $t)
			$arr[] = array('ID'=>$t, 'LABEL'=>$t);

		$data = array(
			'tables'=>$arr,
		);
		
		return $this->generatePage($data);
	}
	
	public function gensql_action()
	{
		
		$insert = $this->genStandardInsert($_POST['table']);
		$update = $this->genStandardUpdate($_POST['table']);
		$delete = $this->genStandardDelete($_POST['table']);
		
		$data = array(
			'insert'=>$insert,
			'update'=>$update,
			'delete'=>$delete
		);
		
		return $this->generatePage($data);
	}
	
	public function genmxmlform_action()
	{
		$cols = $this->getColumnNames($_POST['table']);
		$arr = array();
		foreach($cols as $c)
			$arr[] = strtoupper($c);
			
		$insert = $this->genStandardInsert($_POST['table']);
		$update = $this->genStandardUpdate($_POST['table']);
		$select = $this->genStandardSelect($_POST['table']);
			
		//print_r($arr);exit;
		$data = array(
			'table' => $_POST['table'],
			'cols' => $arr,
			'insert' => $insert,
			'update' => $update,
			'select' => $select,
		);
		
		header("Content-type: text/plain");
		echo $this->generatePage($data);
		exit;
	}
	
	public function genmxmltable_action()
	{
		$cols = $this->getColumnNames($_POST['table']);
		$arr = array();
		foreach($cols as $c)
			$arr[] = strtoupper($c);
			
		//$insert = $this->genStandardInsert($_POST['table']);
		//$update = $this->genStandardUpdate($_POST['table']);
		$select = $this->genStandardSelect($_POST['table']);
		$delete = $this->genStandardDelete($_POST['table']);
			
		//print_r($arr);exit;
		$data = array(
			'table' => $_POST['table'],
			'cols' => $arr,
			//'insert' => $insert,
			//'update' => $update,
			'select' => $select,
			'delete' => $delete
		);
		
		header("Content-type: text/plain");
		echo $this->generatePage($data);
		exit;
	}
}
?>